<?php
class Article_cateModel extends MongoModel {
    var $table  = 'article_cate';
    var $name = '文章分类';
    
//     public function get_by_key($key, $lang=null, $columns=null){
//     	if($lang==null)$lang = LANGUAGE;
//     	$cate = parent::get_by_key($key, $columns);
//     	if(empty($cate))
//     		return null;
//     	if(isset($cate[$lang])){
//     		foreach($cate[$lang] as $k=>$v){
//     			$cate[$k] = $v;
//     		}
//     		unset($cate[$lang]);
//     	}
// //    	$user_level = array();
// //    	if(isset($cate['user_level'])){
// //    		foreach($cate[$lang] as $k=>$v){
// //    			$user_level[] = 
// //    		}
// //    	}
//     	return $cate;
//     }
    
    public function get_cates($site_id, $columns=null, $lang=null){
    	if($lang==null) $lang = LANGUAGE;
    	$cates = self::find(array('site_id'=>$site_id), $columns);
    	foreach($cates as $cate_id=>&$cate){
	    	if(isset($cate[$lang])){
	    		foreach($cate[$lang] as $k=>$v){
	    			$cate[$k] = $v;
	    		}
	    		unset($cate[$lang]);
	    	}
    	}
    	return $cates;
    }
    
    private static $cates = array();
    public static function get_cate_by_key($key){
    	if(isset(self::$cates[$key])){
    		return self::$cates[$key];
    	}
    	$mod = new Article_cateModel();
    	$cate = $mod->get_by_key_site_limit($key);
    	if(!empty($cate)){
    		//初始化链接
    		$cate['url'] = $cate['path'] . '/';
    		self::$cates[$key] = $cate;
    	}
    	return $cate;
    }
}

?>